--[[/**
-- * 
 * 改变能量，溢出则增加buff
 *
 * @author heyang
-- *
-- */]]

---@class BuffEffect534100 : BaseBuffEffect
BuffEffect534100 = ClientFight.CreateClass("BuffEffect534100", ClientFight.BaseBuffEffect)
local t = BuffEffect534100

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters = {...};
    local target = parameters[1];--我当前攻击的目标
    if (target == buff.target) then
        --不能对自己放
        return IBuffEffect.FAIL;
    end
    if not parameters[3] then
        return IBuffEffect.FAIL;
    end
    local result = parameters[3];
    if (not AttackUtils.isDamage(result.state)) then
        return IBuffEffect.FAIL;
    end
    if (not result:isDamage()) then
        return IBuffEffect.FAIL;
    end
    local source = buff.source;
    local buffEffectValue = buff.buffBean.f_BuffEffectValue;
    local addBuffId = 0;
    for i = 1, table.getn(buffEffectValue), 2 do
        local skillId = buffEffectValue[i];
        local buffId = buffEffectValue[i + 1];
        if (t:containsSkillId(skillId, source)) then
            addBuffId = buffId;
            break ;
        end
    end
    if (addBuffId == 0) then
        return IBuffEffect.FAIL;
    end
    BuffManager.addBuff(fight, buff.skill, source, target, false, addBuffId, 1);
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
end
function t:containsSkillId(skillId, source)
    local skills = source.skills;
    for k, skill in pairs(skills) do
        if (skill.skillId == skillId) then
            return true;
        end
    end
    local passiveskills = source.passiveskills;
    for k, skill in pairs(passiveskills) do
        if (skill.skillId == skillId) then
            return true;
        end
    end
    return false;

end
t.New()